#!/usr/bin/bash


token=`kubeadm token list | sed -n "2, 1p" | awk '{print $1}'`
hash=`openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //'`

header="kubeadm join 192.168.1.13:6443 --token"
cert="--discovery-token-ca-cert-hash"
prefix="sha256:"
plane="--control-plane"

if [ "$1"x == "node"x ];then
        k8s_join="$header $token $cert $prefix$hash"
else
        k8s_join="$header $token $cert $prefix$hash $plane"
fi

echo $k8s_join

